package com.talkweb.securitycamera.data.hadoopFile;

import com.talkweb.securitycamera.common.constans.FileType;
import ohos.app.Context;

import java.util.HashMap;
import java.util.Map;

/**
 * 分布式文件存储工厂
 */
public class HadoopFileFactory {

    private static class PolicyFactoryHolder {
        public static HadoopFileFactory instance = new HadoopFileFactory();
    }

    private HadoopFileFactory() {

    }

    /**
     * 分布式文件对象缓存
     */
    private Map<Integer, BaseMediaProcessor> policyMap = new HashMap();

    public static HadoopFileFactory getInstance() {
        return PolicyFactoryHolder.instance;
    }


    public synchronized BaseMediaProcessor getMediaProcessor(FileType type, Context ctx) {
        BaseMediaProcessor processor = policyMap.get(type.getValue());
        if (processor == null) {
            processor = createProcessor(type, ctx);
        }
        return processor;
    }

    private BaseMediaProcessor createProcessor(FileType type, Context ctx) {
        if (type == FileType.FILE_TYPE_IMAGE) {
            return new SimpleImageProcessor(ctx);
        } else if (type == FileType.FILE_TYPE_VIDEO) {
            return new SimpleVideoProcessor(ctx);
        }
        return null;
    }

}
